package com.hamster.crmpre.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hamster.crmpre.mapper.EmployeePerformanceMapper;
import com.hamster.crmpre.mapper.ExecutivePerformanceMapper;
import com.hamster.crmpre.pojo.EmployeePerformance;
import com.hamster.crmpre.pojo.ExecutivePerformance;
import com.hamster.crmpre.service.ExecutivePerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/25 11:37
 * @description：主管业绩接口实现类
 * @modified By：
 * @version: 1.0
 */
@Service
public class ExecutivePerformanceServiceImpl implements ExecutivePerformanceService {

    @Autowired
    private ExecutivePerformanceMapper executivePerformanceMapper;

    /**
     * 根据当前登录者id查询主管业绩信息
     * @param userId 上级经理id
     * @return
     */
    @Override
    public List<ExecutivePerformance> list(String userId) {
        QueryWrapper<ExecutivePerformance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("employee_id",userId).orderByDesc("create_time");
        return executivePerformanceMapper.selectList(queryWrapper);
    }

    /**
     * 根据主管用户id获取主管业绩
     * @param userId 主管用户id
     * @return 一条主管业绩
     */
    @Override
    public ExecutivePerformance get(String userId) {
        return executivePerformanceMapper.selectById(userId);
    }

    /**
     * 根据时间获取主管业绩
     * @param userId 当前登录人id
     * @param time 选取的开始时间
     * @return
     */
    @Override
    public List<ExecutivePerformance> getByTime(String userId, Date time) {
        QueryWrapper<ExecutivePerformance> queryWrapper = new QueryWrapper<>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.MONTH,1);
        Date nextMonthTime = cal.getTime();
        queryWrapper.eq("employee_id", userId);
        queryWrapper.ge("create_time", time).le("create_time", nextMonthTime);
        return executivePerformanceMapper.selectList(queryWrapper);
    }


}
